package com.example.hospital.util;

import com.example.hospital.constant.UserConstants;
import lombok.AllArgsConstructor;

public class UserHolder {
    @AllArgsConstructor
    private static class User {
        private String phone;
        private UserConstants.Role role;
    }

    private static final ThreadLocal<User> tl = new ThreadLocal<>();

    public static void saveUser(String phone, UserConstants.Role role) {
        tl.set(new User(phone, role));
    }

    public static String getUserPhone() {
        if (tl.get() == null) {
            return null;
        }
        return tl.get().phone;
    }

    public static UserConstants.Role getUserRole() {
        if (tl.get() == null) {
            return null;
        }
        return tl.get().role;
    }

    public static void removeUser() {
        tl.remove();
    }
}
